home *** CD-ROM | disk | FTP | other *** search
- Path: hptemp1.cc.umr.edu!jlu
- From: jlu@cs.umr.edu (Eric Jui-Lin Lu)
- Newsgroups: comp.lang.c++
- Subject: Help! Macro replacement......
- Date: 9 Apr 1996 20:11:46 GMT
- Organization: Computer Science Dept, Univ. of Missouri-Rolla
- Message-ID: <4kega2$1tk@hptemp1.cc.umr.edu>
- NNTP-Posting-Host: nag3.cs.umr.edu
-
-
- Hi *,
-
- I wrote an ugly macro definition which, when I compiled, surprised
- me. The macro is defined as
-
- #define ABS(X) ((X <= 0) ? -X : X)
-
- And I called the macro by using
-
- int y = ABS(-6+4);
-
- I expected y would be 10. However, Solaris CC and Turbo C++ version 3.0
- for DOS returned compilation error. And IRIX CC and g++ version 2.6.3
- and 2.7.0 returned 10.
-
- The problem is clear that one replacement gives
-
- int y = --6+4; // compilation error
-
- And the other gives
-
- int y = - -6+4; // y = 10
-
- I tried to find out the answer from Chap 16 of ANSI C++ standard
- draft but cannot figure out which one is correct. Will someone
- please EMAIL me which one conforms to ANSI C++? If interested, I
- can post the summary. Thanks!
-
-
- --Eric
-
- --
- ***************************************--- Eric Jui-Lin Lu ---*
- * Obviousness is always the enemy of * \ jlu@umr.edu / *
- * correctness. -- Bertrand Russell * / http://www.cs.umr.edu/~jlu \ *
- ***************************************--- Univ. of Missouri-Rolla ---*
-